package com.leetcode.LC;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class LC728 {
    public List<Integer> selfDividingNumbers(int left, int right) {

        ArrayList<Integer> list = new ArrayList<>();
        boolean f;
        for (int i = left; i <= right; i++) {
            f=false;
            String s = String.valueOf(i);
            if (s.contains("0")){
                continue;
            }
            for (Integer integer : splitNumber(i)) {
                if (i%integer!=0){
                    f=true;
                    break;
                }
            }
            if (f==false){
                list.add(i);
            }
        }
        return list;
    }
    public Set<Integer> splitNumber(int n) {
        int num ;
        HashSet<Integer> set = new HashSet<>();
        while (n != 0) {
            num = n % 10;
            n /= 10;
            if (num != 0) {
                set.add(num);
            }
        }
        return set;
    }

    public static void main(String[] args) {
        for (Integer selfDividingNumber : new LC728().selfDividingNumbers(1, 22)) {
            System.out.print(selfDividingNumber+",");
        }
    }
}
